var scene,
    camera,
    renderer;
//场景初始化
function init(){
    scene= new THREE.Scene();//初始化场景
    //透视相机 远近高低各不同
    camera =new THREE.PerspectiveCamera(
        90,//角度
        document.body.clientWidth/document.body.clientHeight,
        0.1,
        100
    );
    camera.position.set(0,0,3);
    //opengl在web的实现 3D图形 计算机图形学
    renderer=new THREE.WebGLRenderer({
        antialias: true //优化 抗锯齿
    });
    renderer.setSize(
        document.body.clientWidth,
        document.body.clientHeight
    )
    document
        .getElementById('container')
        .appendChild(renderer.domElement)
        var controls = new THREE.OrbitControls(camera, 
            renderer.domElement);    
        loadCarModal();
        addLight();
        loop();

}
function addLight(){
    var ambientLight=new THREE.AmbientLight(0xd5d5d5);
    ambientLight.intensity=1.2;
    scene.add(ambientLight);
}
function loadCarModal(){
    const loader=new THREE.GLTFLoader();
    loader.load('./images/model.gltf',
    function(gltf){
        scene.add(gltf.scene);
    },
    function(xhr){
        console.log((xhr.loaded/xhr.total*100)+ '% loaded');
    },
    function(error){
        console.log('An error haapened');
    }
    )
}
function loop(){
    //显卡的显示帧率
    requestAnimationFrame(loop);
    renderer.render(scene, camera);
}
window.onload=init; 